/*
 *  Forismatic
 *  
 *  Adds quote into target element.
 *  
 *  Note: This script should be situated after target quote element.
 *
 *  API URL: http://en.forismatic.com/api/
 *
 *  getQuote Method
 *  Selects a random quote using passed numeric key, if the key is not specified the server generates a random key. 
 *  The key influences the choice of quotation. 
 *  Request parameters:
 *      method=getQuote     — method name to invoke
 *      format=<format>     — one of the server supported response formats
 *      key=<integer>       — numeric key, which influences the choice of quotation, the maximum length is 6 characters
 *      lang=<string>       — response language ("ru" or "en")
 *      jsonp=<string>      — callback function name, used for jsonp format only
 */

/**
 *  Shows quote inside target element
 *  @param response defines server response
 */
function showQuote(response) {
    if(!response || !response.quoteText) return;
    var $blockquote = $('#blockquote').html('');
    
    $blockquote.bind('dblclick', function(){
        window.open(response.quoteLink, 'forismatic', 'width=650, height=450')
    });
    
    $blockquote.append($('<p>').text(response.quoteText));
    $blockquote.css('padding-top', 5).css('padding-bottom', 5).css('padding-left', 10);
    if(response.quoteAuthor) $blockquote.append($('<small>').text(response.quoteAuthor));
}

// -------------------------------------------------------------------------- //
document.write('<style type="text/css">blockquote:hover { background-color: whiteSmoke; border-top-left-radius: 6px; border-bottom-left-radius: 6px; -webkit-border-radius: 6px 0 0 6px; }</style>');
document.write('<script id="getQuote" type="text/javascript" src="http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=showQuote"></script>');